 #region imported Namespaces
using System;
using System.Data;
using System.Data.SqlClient;
using BO = PHSRAG.Insight21.BusinessObjects;
using Utility = PHSRAG.Utility;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
//////using ISecurityPolicy = PHSRAG.Insight21.Policy.ISecurityPolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class Salary Grid
	/// <summary>
	/// Salary Grid class defines the method for loading the salary grid data for the specified EmployeeJobMapId.
	/// </summary>
	public class SalaryGrid : BO.BusinessObject
	{
		#region Constants
		private const string SalaryGridKey = "SalaryGrid_7E9428E5-6B05-477C-A626-5EE0D1CCFF02";
		private const string SalaryGridTableName = "SalaryGrid";
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the state of this object
		/// </summary>
		public SalaryGrid(ICachePolicy cachePolicy) : base(cachePolicy)
		{
			DataContainer = new DataSet();
		}
		#endregion

		#region Properties

		/// <summary>
		/// EmployeeJobMapId
		/// </summary>
		public int PerEmployeeJobMapId
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["PerEmployeeJobMapId"];
				return (o == DBNull.Value) ? 0 : (int)o;
			}
		}
		/// <summary>
		/// Employee Name
		/// </summary>
		public string Name
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["Name"];
				return (o == DBNull.Value) ? "" : (string)o;
			}
		}
		/// <summary>
		/// Current Title of the Employee
		/// </summary>
		public string CurrentTitle
		{
			get
				{
					object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["CurrentTitle"];
					return (o == DBNull.Value) ? "" : (string)o;
				}
		}
		/// <summary>
		/// Annual Salary of the employee.
		/// </summary>
		public decimal CurrentSalary
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["CurrentSalary"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Total Salary of the employee
		/// </summary>
		public decimal TotalSalary
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["TotalSalary"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Research Grant
		/// </summary>
		public decimal ResearchGrant
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["ResearchGrant"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Research Sundry
		/// </summary>
		public decimal ResearchSundry
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["ResearchSundry"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Discretionary / Sundry
		/// </summary>
		public decimal Discretionary
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["Discretionary"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Operating Funds
		/// </summary>
		public decimal OperatingFunds
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["OperatingFunds"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// PO Funds
		/// </summary>
		public decimal POFunds
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["POFunds"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// HMS Funds
		/// </summary>
		public decimal HMSFunds
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["HMSFunds"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// VA
		/// </summary>
		public decimal VA
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["VA"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Other
		/// </summary>
		public decimal Other
		{
			get
			{
				object o = DataContainer.Tables[SalaryGridTableName].Rows[0]["Other"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		#endregion

		#region Business Object Methods
		/// <summary>
		/// Cache the salary Grid object  using the caching policy.
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(SalaryGridKey, this);
		}
		/// <summary>
		/// Uncache the salary grid object using the caching policy.
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(SalaryGridKey);
		}

		/// <summary>
		/// Load the DataSet with Salary Grid data by executing the stored procedure
		/// "GetSalaryGrid".  Throws system exception if an error is encountered 
		/// during the load process.
		/// <param name="connectionString">SQL connection string info.</param>
		/// <param name="args">user defined parameters.</param>
		/// <summary>
		public override void Load(string connectionString, params object[] args)
		{
			if(args.Length != 2)
				throw new Exception("Salary Grid requires EmployeeJobMapId,FiscalYearId parameters.");
			try
			{
				DataContainer.Reset();

				Utility.DataAccess.LoadDataSet(DataContainer, SalaryGridTableName, connectionString, "GetSalaryGrid",
					Utility.DataAccess.BuildSqlParameterArray(
						"@employeeJobMapId", SqlDbType.Int, args[0]
						,"@fiscalYearId",SqlDbType.Int,args[1]
					));
			}
			catch(Exception e)
			{
				Utility.ExceptionReport.WriteToEventLog ("SalaryGrid Load", e, true, Utility.ExceptionReport.ReportType.Error);
			}
		}
		#endregion

	}
	#endregion
}
